from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime


class VideoFormatInfo(BaseModel):
    """视频格式信息DTO"""
    format_id: str = Field(..., description="格式ID")
    ext: str = Field(..., description="文件扩展名")
    resolution: str = Field(..., description="分辨率")
    filesize: Optional[int] = Field(None, description="文件大小(字节)")
    filesize_approx: Optional[int] = Field(None, description="文件大小(大约)")
    url: Optional[str] = Field(None, description="下载链接")
    quality: Optional[float] = Field(None, description="质量分数")
    format_note: Optional[str] = Field(None, description="格式说明")


class YouTubeVideoInfo(BaseModel):
    """YouTube视频信息DTO"""
    video_id: str = Field(..., description="视频ID")
    title: str = Field(..., description="视频标题")
    uploader: Optional[str] = Field(None, description="上传者")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    view_count: Optional[int] = Field(None, description="观看次数")
    upload_date: Optional[str] = Field(None, description="上传日期")
    description: Optional[str] = Field(None, description="视频描述")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    formats: List[VideoFormatInfo] = Field(default_factory=list, description="可用格式列表")


class YouTubeInfoResponse(BaseModel):
    """获取YouTube视频信息响应DTO"""
    video_id: str = Field(..., description="视频ID")
    title: str = Field(..., description="视频标题")
    uploader: Optional[str] = Field(None, description="上传者")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    view_count: Optional[int] = Field(None, description="观看次数")
    upload_date: Optional[str] = Field(None, description="上传日期")
    description: Optional[str] = Field(None, description="视频描述")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    formats: List[VideoFormatInfo] = Field(default_factory=list, description="可用格式列表")


class YouTubeDownloadUrlInfo(BaseModel):
    """YouTube下载链接信息DTO"""
    video_id: str = Field(..., description="视频ID")
    title: str = Field(..., description="视频标题")
    download_url: str = Field(..., description="下载链接")
    format: str = Field(..., description="视频格式")
    resolution: str = Field(..., description="分辨率")
    filesize: Optional[int] = Field(None, description="文件大小(字节)")
    filesize_approx: Optional[int] = Field(None, description="文件大小(大约)")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")


class YouTubeDownloadUrlResponse(BaseModel):
    """获取YouTube下载链接响应DTO"""
    video_id: str = Field(..., description="视频ID")
    title: str = Field(..., description="视频标题")
    download_url: str = Field(..., description="下载链接")
    format: str = Field(..., description="视频格式")
    resolution: str = Field(..., description="分辨率")
    filesize: Optional[int] = Field(None, description="文件大小(字节)")
    filesize_approx: Optional[int] = Field(None, description="文件大小(大约)")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")


class YouTubeDownloadInfo(BaseModel):
    """YouTube下载信息DTO"""
    video_id: str = Field(..., description="视频ID")
    title: str = Field(..., description="视频标题")
    filename: str = Field(..., description="文件名")
    file_size: int = Field(..., description="文件大小(字节)")
    file_size_display: str = Field(..., description="文件大小(格式化显示)")
    format: str = Field(..., description="视频格式")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    local_path: Optional[str] = Field(None, description="本地文件路径")
    qiniu_url: Optional[str] = Field(None, description="七牛云链接")
    qiniu_key: Optional[str] = Field(None, description="七牛云存储键")
    qiniu_error: Optional[str] = Field(None, description="七牛云上传错误信息")


class YouTubeDownloadResponse(BaseModel):
    """YouTube视频下载响应DTO"""
    video_id: str = Field(..., description="视频ID")
    title: str = Field(..., description="视频标题")
    filename: str = Field(..., description="文件名")
    file_size: int = Field(..., description="文件大小(字节)")
    file_size_display: str = Field(..., description="文件大小(格式化显示)")
    format: str = Field(..., description="视频格式")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    local_path: Optional[str] = Field(None, description="本地文件路径")
    qiniu_url: Optional[str] = Field(None, description="七牛云链接")
    qiniu_key: Optional[str] = Field(None, description="七牛云存储键")
    qiniu_error: Optional[str] = Field(None, description="七牛云上传错误信息")


class YouTubeSupportedQualitiesResponse(BaseModel):
    """YouTube支持的质量选项响应DTO"""
    qualities: List[str] = Field(..., description="支持的质量选项")
    default_quality: str = Field(..., description="默认质量")
    description: str = Field(..., description="说明") 
 